; *** Hasami Shogi
; *** Copyright 1998-2002 Zillions Development
; v.2.0

; You need to purchase Zillions of Games to load this rules file
; Visit the Zillions web site at http://www.zillions-of-games.com

(version "2.0")
(translate 
 ("Black" "黑方") ("White" "白方")
 ("disk" "棋子")
 ("5-in-a-Row" "剪刀将棋-五连")("5-in-a-Row - No Diagonals" "剪刀将棋-直五连")
 ("5-in-a-Row - Slow" "剪刀将棋-单步")
 ("War - 9 Men Each, No Jumping" "剪刀将棋-吃子大战 9子")
 ("War - 18 Men Each" "剪刀将棋-吃子大战 18子")
 ("War - Slow" "剪刀将棋-吃子大战 18子单步")
)

(define check-direction
    (if (enemy? $1) ; Is there an enemy this direction?
    	mark
		$1
    	(while (enemy? $1) $1) ; Skip to end of line
		(if (friend? $1)
			(set-flag move-found true)		
			back
			(while (enemy? $1) $1 capture)
		 else
		   (if (in-zone? corners) (set-flag corner-stopped true))
		)
		back
	)
)

(define jump-or-shift (
   $1
   (set-flag corner-stopped false)
   (if not-empty?
      $1
      (if empty?
         (check-direction $1)
         (check-direction $2)
         (check-direction $3)
		 (if (and $4 (flag? corner-stopped))
		    (check-direction clockwise)
			(check-direction counter-clockwise)
		 )
         add
      )
    else
         (check-direction $1)
         (check-direction $2)
         (check-direction $3)
         (if (and $4 (flag? corner-stopped))
		    (check-direction clockwise)
			(check-direction counter-clockwise)
            (set-flag corner-stopped false)
         )
         add
   )
))

(define jump-or-slide (
   $1
   (set-flag corner-stopped false)
   (if not-empty?
      $1
      (if empty?
         (check-direction $1)
         (check-direction $2)
         (check-direction $3)
         (if (and $4 (flag? corner-stopped))
		    (check-direction clockwise)
			(check-direction counter-clockwise)
         )
         add
      )
    else
      (while empty?
         (check-direction $1)
         (check-direction $2)
         (check-direction $3)
         (if (and $4 (flag? corner-stopped))
		    (check-direction clockwise)
			(check-direction counter-clockwise)
            (set-flag corner-stopped false)
         )
         add
         $1 ; Move to next
      )
   )
))

(define slide (
   $1
   (set-flag corner-stopped false)
   (while empty?
         (check-direction $1)
         (check-direction $2)
         (check-direction $3)
		 (if (and $4 (flag? corner-stopped))
		    (check-direction clockwise)
			(check-direction counter-clockwise)
            (set-flag corner-stopped false)
		 )
         add
         $1 ; Move to next
   )
))

(define uW ($1 Wn) ($1 We) ($1 Wne) ($1 Wse))
(define uB ($1 Bn) ($1 Be) ($1 Bne) ($1 Bse))

(define slow-piece
   (piece
	    (name disk)
	    (image White "images\Hasami_Shogi\Shaag\WStone.bmp" "images\Hasami_Shogi\WStone.bmp"
	           Black "images\Hasami_Shogi\Shaag\BStone.bmp" "images\Hasami_Shogi\BStone.bmp")
	    (help "棋子可横向或纵向移动1格。夹吃。")
	    (description "* 可以横向或纵向移动一格。
	       \* 可以跳过相邻棋子到其后的空格。\\
		若走子之后横向或纵向包夹对方的至少一个棋子，则被包夹的那些棋子被吃。")
	    (moves
		    (jump-or-shift n e w false)
		    (jump-or-shift s e w false)
		    (jump-or-shift e n s false)
		    (jump-or-shift w n s false)
	    )
    )
)

; *** Hasami Shogi: 5-in-a-Row Variants

(game
   (title "5-in-a-Row")
   (description "先在己方两条横线以外将五个棋子横、直或斜连成一条线为胜。\\
       棋子可以横向或纵向移动，不限格数。还可跳过相邻子到后面的空格。若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。")
   (history "This game is often played using Go stones on a Shogi board or
       on a quarter of a Go board,  playing on the squares rather than the intersections.   It
       is a relative of Go-Moku and Ninuki-Renju.")
   (strategy "Whenever your stone comes into contact with an enemy stone
       vertically or horizontally, look for capturing possibilities!  You
       may find that a diagonal line of stones is harder to capture.")
   (option "prevent flipping" 2)
   (opening-sound "Audio\\Japan1.wav")
   (win-sound "Audio\\Japan2.wav")
   (loss-sound "Audio\\Japan2.wav")
   (click-sound "Audio\\WoodClick.wav")
   (release-sound "Audio\\WoodClick.wav")
   (capture-sound "Audio\\WoodClick.wav")
   (move-sound "Audio\\Flute.wav")
   (players Black White)
   (turn-order Black White)
   (option "pass turn" forced)
   (board
      (image "images\Hasami_Shogi\Shaag\Hasami.bmp" "images\Hasami_Shogi\Hasami.bmp")
      (grid
         (start-rectangle 6 6 58 58)
         (dimensions
             ("a/b/c/d/e/f/g/h/i" (56 0)) ; files
             ("9/8/7/6/5/4/3/2/1" (0 56)) ; ranks
         )
         (directions (n 0 -1) (e 1 0) (s 0 1) (w -1 0)
                     (ne 1 -1) (nw -1 -1) (se 1 1) (sw -1 1)
                     (Bn 0 -1) (Be 1 0) (Bne 1 -1) (Bse 1 1)
                     (Wn 0 1) (We 1 0) (Wne 1 1) (Wse 1 -1)
         )
      )
      (unlink (uB a1) (uB b1) (uB c1) (uB d1) (uB e1) (uB f1) (uB g1) (uB h1) (uB i1) 
              (uB a2) (uB b2) (uB c2) (uB d2) (uB e2) (uB f2) (uB g2) (uB h2) (uB i2)
              (uW a8) (uW b8) (uW c8) (uW d8) (uW e8) (uW f8) (uW g8) (uW h8) (uW i8) 
	      (uW a9) (uW b9) (uW c9) (uW d9) (uW e9) (uW f9) (uW g9) (uW h9) (uW i9)
              (a3 Bse) (b3 Bse) (c3 Bse) (d3 Bse) (e3 Bse) (f3 Bse) (g3 Bse) (h3 Bse) (i3 Bse)
              (a7 Wse) (b7 Wse) (c7 Wse) (d7 Wse) (e7 Wse) (f7 Wse) (g7 Wse) (h7 Wse) (i7 Wse)
      )
      (links counter-clockwise
	     (a1 b1) (b1 c1) (c1 d1) (d1 e1) (e1 f1) (f1 g1) (g1 h1) (h1 i1)
	     (i1 i2) (i2 i3) (i3 i4) (i4 i5) (i5 i6) (i6 i7) (i7 i8) (i8 i9)
	     (i9 h9) (h9 g9) (g9 f9) (f9 e9) (e9 d9) (d9 c9) (c9 b9) (b9 a9)
	     (a9 a8) (a8 a7) (a7 a6) (a6 a5) (a5 a4) (a4 a3) (a3 a2) (a2 a1)
      )
      (links clockwise
	     (a9 b9) (b9 c9) (c9 d9) (d9 e9) (e9 f9) (f9 g9) (g9 h9) (h9 i9)
	     (i9 i8) (i8 i7) (i7 i6) (i6 i5) (i5 i4) (i4 i3) (i3 i2) (i2 i1)
	     (i1 h1) (h1 g1) (g1 f1) (f1 e1) (e1 d1) (d1 c1) (c1 b1) (b1 a1)
	     (a1 a2) (a2 a3) (a3 a4) (a4 a5) (a5 a6) (a6 a7) (a7 a8) (a8 a9)
      )
      (zone
         (name corners)
         (players Black White)
         (positions a1 i1 a9 i9)
      )
   )
   (board-setup
      (White (disk a8 a9 b8 b9 c8 c9 d8 d9 e8 e9 f8 f9 g8 g9 h8 h9 i8 i9))
      (Black (disk a1 a2 b1 b2 c1 c2 d1 d2 e1 e2 f1 f2 g1 g2 h1 h2 i1 i2))
   )
   (piece
      (name disk)
      (image White "images\Hasami_Shogi\Shaag\WStone.bmp" "images\Hasami_Shogi\WStone.bmp"
             Black "images\Hasami_Shogi\Shaag\BStone.bmp" "images\Hasami_Shogi\BStone.bmp")
      (help "Disk: moves like a Rook or leaps over piece, sandwich captures")
      (description "* 可以横向或纵向移动，不限格数。
	       \* 可以跳过相邻棋子到其后的空格。\\
		若走子之后横向或纵向包夹对方的至少一个棋子，则被包夹的那些棋子被吃。")
      (moves
         (jump-or-slide n e w false)
         (jump-or-slide s e w false)
         (jump-or-slide e n s false)
         (jump-or-slide w n s false)
      )
    )
    (win-condition (White)
        (or (relative-config disk Wn disk Wn disk Wn disk Wn disk)
            (relative-config disk We disk We disk We disk We disk)
            (relative-config disk Wne disk Wne disk Wne disk Wne disk)
            (relative-config disk Wse disk Wse disk Wse disk Wse disk)
       )
    )
    (win-condition (Black)
        (or (relative-config disk Bn disk Bn disk Bn disk Bn disk)
            (relative-config disk Be disk Be disk Be disk Be disk)
            (relative-config disk Bne disk Bne disk Bne disk Bne disk)
            (relative-config disk Bse disk Bse disk Bse disk Bse disk)
       )
    )
)

(variant
    (title "5-in-a-Row - No Diagonals")
    (description "先在己方两条横线以外将五个棋子横向或纵向连成一条线为胜。\\
       棋子可以横向或纵向移动，不限格数。还可跳过相邻子到后面的空格。若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。")
    (win-condition (White)
        (or (relative-config disk Wn disk Wn disk Wn disk Wn disk)
            (relative-config disk We disk We disk We disk We disk)
       )
    )
    (win-condition (Black)
        (or (relative-config disk Bn disk Bn disk Bn disk Bn disk)
            (relative-config disk Be disk Be disk Be disk Be disk)
       )
    )
)

(variant
   (title "5-in-a-Row - Slow")
   (description "先在己方两条横线以外将五个棋子横、直或斜连成一条线为胜。\\
       棋子可以横向或纵向移动一格，或跳过相邻子到后面的空格。若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。")
   (slow-piece)
   (win-condition (White)
        (or (relative-config disk Wn disk Wn disk Wn disk Wn disk)
            (relative-config disk Wne disk Wne disk Wne disk Wne disk)
            (relative-config disk Wse disk Wse disk Wse disk Wse disk)
       )
   )
   (win-condition (Black)
        (or (relative-config disk Bn disk Bn disk Bn disk Bn disk)
            (relative-config disk Bne disk Bne disk Bne disk Bne disk)
            (relative-config disk Bse disk Bse disk Bse disk Bse disk)
       )
   )
)

(variant
   (title "-")
)

; *** Hasami Shogi: War Variants

(variant
   (title "War - 9 Men Each, No Jumping")
   (description "先吃光对手或使对方只剩一个棋子者胜。\\棋子可以横向或纵向移动，不限格数。还可跳过相邻子到后面的空格。若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。吃子时，棋盘的上下左右边界视为相连的。")
   (history "This game is popular with Japanese children.  It can also be played on a
           Shogi board with Shogi pawns.")
   (piece
	    (name disk)
	    (image White "images\Hasami_Shogi\SHaag\WStone.bmp" "images\Hasami_Shogi\WStone.bmp"
	           Black "images\Hasami_Shogi\SHaag\BStone.bmp" "images\Hasami_Shogi\BStone.bmp")
	    (help "Disk: moves like a Rook, sandwich captures")
	    (description "* Slides like a rook in Chess, i.e.
	       any number of empty spaces up, down, left, or right.
	       \\Capturing
	       is achieved by sandwiching your opponent's pieces between yours
	       along a row or column.  This is similar to Reversi, except that
	       the pieces are removed from the board instead of flipped.  Sandwich
	       captures that wrap around edges are allowed.")
	    (moves
		    (slide n e w true)
		    (slide s e w true)
		    (slide e n s true)
		    (slide w n s true)
	    )
    )
    (board-setup
      (White (disk a9 b9 c9 d9 e9 f9 g9 h9 i9))
      (Black (disk a1 b1 c1 d1 e1 f1 g1 h1 i1))
    )
    (loss-condition (White Black) (pieces-remaining 1) )
    (loss-condition (White Black) (pieces-remaining 0) )
)

(variant
   (title "War - 18 Men Each")
   (description "先吃光对手或使对方只剩一个棋子者胜。\\
	棋子可以横向或纵向移动，不限格数。还可跳过相邻子到后面的空格。\
	若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。吃子时，棋盘的上下左右边界视为相连的。")
   (piece
	    (name disk)
	    (image White "images\Hasami_Shogi\SHaag\WStone.bmp" "images\Hasami_Shogi\WStone.bmp"
	           Black "images\Hasami_Shogi\SHaag\BStone.bmp" "images\Hasami_Shogi\BStone.bmp")
	    (help "Disk: moves like a Rook or leaps over piece, sandwich captures")
	    (description "* Slides like a rook in Chess, i.e.
	       any number of empty spaces up, down, left, or right.
	       \* Leaps over a piece that is adjacent
	       horizontally or vertically, landing on the other side of
	       the piece, which is left on the board.\\The only capturing
	       is achieved by sandwiching your opponent's pieces between yours
	       along a row or column.  This is similar to Reversi, except that
	       the pieces are removed from the board instead of flipped.  Sandwich
	       captures that wrap around edges are allowed.")
	    (moves
		    (jump-or-slide n e w true)
		    (jump-or-slide s e w true)
		    (jump-or-slide e n s true)
		    (jump-or-slide w n s true)
	    )
    )
    (loss-condition (White Black) (pieces-remaining 1) )
    (loss-condition (White Black) (pieces-remaining 0) )
)


(variant
    (title "War - Slow")
    (description "先吃光对手或使对方只剩一个棋子者胜。\\
	棋子可以横向或纵向移动一格。还可跳过相邻子到后面的空格。\
	若走子之后横向或纵向包夹对方的至少一个棋子，则可以吃掉这些棋子。吃子时，棋盘的上下左右边界视为相连的。")
    (slow-piece)
    (loss-condition (White Black) (pieces-remaining 1) )
    (loss-condition (White Black) (pieces-remaining 0) )
)